package com.travel.server.manager.impl.command.user;

import com.travel.common.util.CollectionUtil;
import com.travel.server.manager.dto.request.EmptyRequest;
import com.travel.server.manager.dto.response.user.QueryDepartmentEnumResponse;
import com.travel.server.manager.dto.response.user.QueryDepartmentEnumResponse.DepartmentEnumItem;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.DepartmentDal;
import com.travel.server.manager.model.DepartmentInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/20 14:40
 * @Desc:
 */
@Component
public class QueryDepartmentEnumCommand extends AbstractCommand<EmptyRequest, QueryDepartmentEnumResponse> {

    @Autowired
    private DepartmentDal departmentDal;

    @Override
    protected void checkInput(EmptyRequest request) {

    }

    @Override
    public QueryDepartmentEnumResponse handle(EmptyRequest request) {
        List<DepartmentInfo> list = departmentDal.selectByExample(null);
        QueryDepartmentEnumResponse response = new QueryDepartmentEnumResponse();
        List<DepartmentEnumItem> departmentList = new ArrayList<>();
        if(!CollectionUtil.isEmpty(list)){
            for(DepartmentInfo info : list){
                DepartmentEnumItem item = new DepartmentEnumItem();
                item.setId(info.getId());
                item.setName(info.getDepartmentName());
                departmentList.add(item);
            }
        }
        response.setDepartmentList(departmentList);
        return response;
    }
}
